package com.module.shici.room;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.fenghuajueli.libbasecoreui.BaseApplication;
import com.module.shici.room.entity.Collect;
import com.module.shici.room.entity.Erge;
import com.module.shici.room.entity.Gongzhugushi;
import com.module.shici.room.entity.Guoxue;
import com.module.shici.room.entity.Shaoerbaike;
import com.module.shici.room.entity.Yinxionggushi;


@Database(entities = {Erge.class, Gongzhugushi.class, Guoxue.class, Shaoerbaike.class, Yinxionggushi.class, Collect.class}, version = 1, exportSchema = false)
public abstract class MusicDataBase extends RoomDatabase {

    private static final String DB_NAME = "music.db";
    private static volatile MusicDataBase instance;

    public static synchronized MusicDataBase getInstance() {
        if (instance == null) {
            instance = create();
        }
        return instance;
    }

    private static MusicDataBase create() {
        return Room.databaseBuilder(
                BaseApplication.getApplication(),
                MusicDataBase.class,
                DB_NAME)
                .createFromAsset("yinpin.db")//从assets复制
                .allowMainThreadQueries()//允许在主线程允许
                .build();
    }

    public abstract MusicDao getMusicDao();
}
